/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Andre
 */
@Entity
@Table(name = "contrato")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Contrato.findAll", query = "SELECT c FROM Contrato c"),
    @NamedQuery(name = "Contrato.findByIdContrato", query = "SELECT c FROM Contrato c WHERE c.idContrato = :idContrato"),
    @NamedQuery(name = "Contrato.findByDataContrato", query = "SELECT c FROM Contrato c WHERE c.dataContrato = :dataContrato"),
    @NamedQuery(name = "Contrato.findByPerDesconto", query = "SELECT c FROM Contrato c WHERE c.perDesconto = :perDesconto")})
public class Contrato implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idContrato")
    private Integer idContrato;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "dataContrato")
    @Temporal(TemporalType.DATE)
    private Date dataContrato;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "perDesconto")
    private double perDesconto;
    
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 65535)
    @Column(name = "observacao")
    private String observacao;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "contrato")
    private List<CondicoesContrato> condicoesContratoList;
    
    @JoinColumn(name = "idResponsavel", referencedColumnName = "idPessoa")
    @ManyToOne(optional = false)
    private Funcionario responsavel;
    
    @JoinColumn(name = "idCliente", referencedColumnName = "idPessoa")
    @ManyToOne(optional = false)
    private Cliente cliente;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "contrato")
    private List<Matricula> matriculaList;

    public Contrato() {
    }

    public Contrato(Date dataContrato) {
        this.dataContrato = dataContrato;
    }

    public Contrato(Date dataContrato, double perDesconto, String observacao) {
        this.dataContrato = dataContrato;
        this.perDesconto = perDesconto;
        this.observacao = observacao;
    }

    public Integer getIdContrato() {
        return idContrato;
    }

    public Date getDataContrato() {
        return dataContrato;
    }

    public void setDataContrato(Date dataContrato) {
        this.dataContrato = dataContrato;
    }

    public double getPerDesconto() {
        return perDesconto;
    }

    public void setPerDesconto(double perDesconto) {
        this.perDesconto = perDesconto;
    }

    public String getObservacao() {
        return observacao;
    }

    public void setObservacao(String observacao) {
        this.observacao = observacao;
    }

    @XmlTransient
    public List<CondicoesContrato> getCondicoesContratoList() {
        return condicoesContratoList;
    }

    public void setCondicoesContratoList(List<CondicoesContrato> condicoesContratoList) {
        this.condicoesContratoList = condicoesContratoList;
    }

    public Funcionario getResponsavel() {
        return responsavel;
    }

    public void setResponsavel(Funcionario responsavel) {
        this.responsavel = responsavel;
    }

    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idContrato != null ? idContrato.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Contrato)) {
            return false;
        }
        Contrato other = (Contrato) object;
        if ((this.idContrato == null && other.idContrato != null) || (this.idContrato != null && !this.idContrato.equals(other.idContrato))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Contrato[ idContrato=" + idContrato + " ]";
    }

    /**
     * @return the matriculaList
     */
    public List<Matricula> getMatriculaList() {
        return matriculaList;
    }

    /**
     * @param matriculaList the matriculaList to set
     */
    public void setMatriculaList(List<Matricula> matriculaList) {
        this.matriculaList = matriculaList;
    }
    
}
